package cn.com.nes.site.controller.workOrder;

import cn.com.nes.common.util.OssImagePathUtils;
import cn.com.nes.common.web.CommonResult;
import cn.com.nes.site.service.workOrder.WorkOrderRecordService;
import cn.com.nes.site.service.workOrder.dto.callCenter.WorkOrderRecordListDto;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author yueb
 */
@RestController()
@RequestMapping("/v2/order/workOrderRecord")
public class WorkOrderRecordController {


    @Resource
    private WorkOrderRecordService workOrderRecordService;

   /* *//**
     * 查看通用工单记录
     *
     * @param voMap 工单记录传参类
     * @param
     * @return 工单id
     *//*
    @PostMapping(value = "/getPublicWorkOrderRecordList")
    public CommonResult<?> getPublicWorkOrderRecordList(@RequestBody HashMap<String, Long> voMap) {
        //获取前台传参的数据
        Long workOrderId = voMap.get("workOrderId");
        if (workOrderId != null) {
            //查看通用工单记录
            List<WorkOrderRecordListDto> workOrderRecordList = workOrderRecordService.getPublicWorkOrderRecordList(workOrderId);
            //判断工单id
            return CommonResult.data(workOrderRecordList);
        } else {
            //错误提示
            return CommonResult.error("工单id为空");
        }
    }
*/
    /**
     * 查看工单记录
     *
     * @param voMap   工单记录传参类
     * @param sessoin
     * @return 工单id
     */
    @PostMapping(value = "/getWorkOrderRecordList")
    public CommonResult<?> getWorkOrderRecordList(@RequestBody HashMap<String, Long> voMap, HttpSession sessoin) {
        //获取前台传参的数据
        Long workOrderId = voMap.get("workOrderId");
        if (workOrderId != null) {
            //查看工单记录
            List<WorkOrderRecordListDto> workOrderRecordList = workOrderRecordService.getWorkOrderRecordList(workOrderId);
            if (CollUtil.isNotEmpty(workOrderRecordList)) {
                for (WorkOrderRecordListDto dto : workOrderRecordList) {
                    if (StrUtil.isNotBlank(dto.getImages())) {
                        String[] images = dto.getImages().split(";");
                        List<String> imageList = new ArrayList<>();
                        for (String image : images) {
                            String imagesPath = OssImagePathUtils.getImgSignURL(image, 1, " https://oss-cn-beijing.aliyuncs.com", "LTAI4GGGPjJdh83sy2vf2Hx3", "LsuL7otABT1a6eIXdhH7dOWcqGeqos", "nescallcenter");
                            imageList.add(imagesPath);
                        }
                        dto.setImageList(imageList);
                    }
                    /*if (StrUtil.isBlank(dto.getName())) {
                        dto.setName("移动端用户");
                    }*/
                }
            }
            //判断工单id
            return CommonResult.data(workOrderRecordList);
        } else {
            //错误提示
            return CommonResult.error("工单id为空");
        }
    }

}
